Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Switch to k8s client-go #15486

Merged
merged 13 commits into from
Feb 12, 2021
Merged

Switch to k8s client-go #15486

merged 13 commits into from
Feb 12, 2021

Conversation

daxmc99
Copy link
Contributor

@daxmc99 daxmc99 commented Nov 5, 2020

Fixes https://github.com/sourcegraph/sourcegraph/issues/11804

This is needed as part of https://github.com/sourcegraph/sourcegraph/issues/13878 since without this we cannot use a current client-go (this client is ~2 years old)

@daxmc99 daxmc99 marked this pull request as ready for review November 5, 2020 23:46
@daxmc99 daxmc99 requested review from uwedeportivo and bobheadxi and removed request for uwedeportivo November 5, 2020 23:46
@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Nov 5, 2020

Notifying subscribers in CODENOTIFY files for diff aedcaf7...263717f.

Notify File(s)
@keegancsmith internal/endpoint/endpoint.go

Copy link
Contributor

@uwedeportivo uwedeportivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please add keegan or somebody from cloud as a reviewer. endpoint.go is used to discover zoekt service endpoints so it's rather important :-)

// namespace returns the namespace the pod is currently running in
// this is done because the k8s client we previously used set the namespace
// when the client was created, the official k8s client does not
func namespace() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please rewrite this a little to log the error if it happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten

@daxmc99 daxmc99 requested a review from keegancsmith November 6, 2020 00:01
@codecov
Copy link

codecov bot commented Nov 6, 2020

Codecov Report

Merging #15486 (817d48d) into main (aedcaf7) will increase coverage by 1.57%.
The diff coverage is 11.26%.

@@            Coverage Diff             @@
##             main   #15486      +/-   ##
==========================================
+ Coverage   50.89%   52.47%   +1.57%     
==========================================
  Files        1736     1614     -122     
  Lines       86759    80634    -6125     
  Branches     7874     7168     -706     
==========================================
- Hits        44156    42311    -1845     
+ Misses      38711    34617    -4094     
+ Partials     3892     3706     -186     
Flag Coverage Δ *Carryforward flag
go 52.55% <11.26%> (+2.81%) ⬆️
integration 28.76% <ø> (-1.56%) ⬇️ Carriedforward from f669e1b
storybook 27.29% <ø> (-3.28%) ⬇️ Carriedforward from f669e1b
typescript 52.27% <ø> (-1.38%) ⬇️ Carriedforward from f669e1b
unit 34.34% <ø> (-1.04%) ⬇️ Carriedforward from f669e1b

*This pull request uses carry forward flags. Click here to find out more.

Impacted Files Coverage Δ
internal/endpoint/endpoint.go 34.95% <0.00%> (-6.00%) ⬇️
cmd/frontend/internal/app/debugproxies/scanner.go 29.72% <25.00%> (-8.30%) ⬇️
client/web/src/tree/Directory.tsx 11.11% <0.00%> (-58.89%) ⬇️
client/web/src/tree/SingleChildTreeLayer.tsx 0.00% <0.00%> (-57.98%) ⬇️
...t/web/src/search/input/toggles/CopyQueryButton.tsx 14.28% <0.00%> (-57.15%) ⬇️
client/web/src/repo/blob/panel/BlobPanel.tsx 42.85% <0.00%> (-54.29%) ⬇️
client/web/src/util/path.tsx 50.00% <0.00%> (-50.00%) ⬇️
client/web/src/insights/InsightsNavLink.tsx 50.00% <0.00%> (-50.00%) ⬇️
...terprise/code-monitoring/CodeMonitoringNavItem.tsx 50.00% <0.00%> (-50.00%) ⬇️
client/web/src/search/QuickLinks.tsx 60.00% <0.00%> (-40.00%) ⬇️
... and 1061 more

Copy link
Contributor

@uwedeportivo uwedeportivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@keegancsmith
Copy link
Member

I'll review the code soon, but at a high level this pulls in a crap load of transitive dependencies. We used to use client-go, and constantly ran into dependency issues due to how much it depends on and how they change.

Why do you need client-go? Does this simple client not solve it for you?

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Some comments inline. This looks like it works, my main concern is that client-go is a seven tonne gorilla that I'd rather avoid in our dependency tree.

@@ -102,21 +85,23 @@ func (cs *clusterScanner) runEventLoop() {
// watchEndpointEvents uses the k8s watch API operation to watch for endpoint events. Spins forever unless an error
// occurs that would necessitate creating a new watcher. The caller will then call again creating the new watcher.
func (cs *clusterScanner) watchEndpointEvents() (bool, error) {
watcher, err := cs.client.Watch(context.Background(), cs.client.Namespace(), new(corev1.Endpoints))

// TODO(Dax): Rewrite this to used NewSharedInformerFactory from k8s/client-go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may have to look at older versions of this repo, but I believe we used to use informer back when this package used client-go.

Comment on lines 97 to +98
for {
var eps corev1.Endpoints
eventType, err := watcher.Next(&eps)
event := <-watcher.ResultChan()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to do for event := range watcher.ResultChan()

cmd/frontend/internal/app/debugproxies/scanner.go Outdated Show resolved Hide resolved
cmd/frontend/internal/app/debugproxies/scanner.go Outdated Show resolved Hide resolved
defer watcher.Close()
func inform(client v1.EndpointsInterface, m *Map, u *k8sURL) error {

// TODO(Dax): We shouldn't use watch directly, use an informer here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI if watch is simpler, we should just use that. I think Informer may be simple, I can't remember exactly :) But Informer is designed to help scale / simplify access, but we only care about simplicity not scale in this case.

eventType, err := watcher.Next(&endpoints)
if err != nil {
return errors.Wrap(err, "watcher.Next")
event := <-watcher.ResultChan()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the previous code snippet, you can for loop over the chan

e := event.Object
endpoints, ok := e.(*corev1.Endpoints)
if !ok {
return errors.Wrap(err, "object from watcher is not an endpoint")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you manually tested this? Should be fine, but this sort of runtime reflection can slip through the cracks.

return "default"
}
return ns
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments from the other place this was copied from.

@daxmc99
Copy link
Contributor Author

daxmc99 commented Nov 9, 2020

After your comment about this pulling in more dependencies, I checked the frontend binary size before and after this change:

before 68M 
after 117M

This is a 72% increase in our binary size which feels excessive for what is essentially a refactor to use a more well-documented client.

I knew that client-go might have some issues with other dependencies but there are no conflicts and the post 1.17.0 versions are fairly easy to update.

@daxmc99
Copy link
Contributor Author

daxmc99 commented Nov 10, 2020

I also spent some time today trying to upgrade https://github.com/ericchiang/k8s but the protobuf generation no longer works

@keegancsmith
Copy link
Member

After your comment about this pulling in more dependencies, I checked the frontend binary size before and after this change:

before 68M 
after 117M

This is a 72% increase in our binary size which feels excessive for what is essentially a refactor to use a more well-documented client.

I knew that client-go might have some issues with other dependencies but there are no conflicts and the post 1.17.0 versions are fairly easy to update.

Yeah I am guessing this has calmed down vs a few years ago.

I also spent some time today trying to upgrade https://github.com/ericchiang/k8s but the protobuf generation no longer works

@daxmc99 you wanna pair tomorrow to try and sort this out? I'm sure making our current dep work on modern protobuf will make others happy.

@daxmc99
Copy link
Contributor Author

daxmc99 commented Dec 2, 2020

The cluster QA tests are currently running via a pure bash implementation.
The results of our pairing session are available here:
ericchiang/k8s#128

The upstream project has been archived though so we should avoid new uses of ericchiang/k8s where possible.

@keegancsmith
Copy link
Member

keegancsmith commented Dec 2, 2020 via email

@daxmc99
Copy link
Contributor Author

daxmc99 commented Dec 3, 2020 via email

@keegancsmith
Copy link
Member

keegancsmith commented Dec 3, 2020 via email

@arussellsaw
Copy link

👋 i'm gonna pick this up to resolve conflicts & merge, as it's blocking some work for secret encryption. The GCloud KMS library depends on a newer protobuf version, and won't compile. I've pulled these changes into my local branch and everything looks fine. context: https://sourcegraph.slack.com/archives/CHPC7UX16/p1613123508259400

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

golang/protobuf dependency breaks things if upgraded to v1.3.5+
6 participants